{template 'public/header'}
{template 'public/comhead'}
<link rel="stylesheet" type="text/css" href="../addons/zh_jypx/template/public/ygcss.css">
<style type="text/css">
    input[type="radio"] + label::before {
        content: "\a0"; /*不换行空格*/
        display: inline-block;
        vertical-align: middle;
        font-size: 16px;
        width: 1em;
        height: 1em;
        margin-right: .4em;
        border-radius: 50%;
        border: 2px solid #ddd;
        text-indent: .15em;
        line-height: 1; 
    }
    input[type="radio"]:checked + label::before {
        background-color: #44ABF7;
        background-clip: content-box;
        padding: .1em;
        border: 2px solid #44ABF7;
    }
    input[type="radio"] {
        position: absolute;
        clip: rect(0, 0, 0, 0);
    }
    .ygmargin{margin-top: 10px;color: #999;}
</style>
<ul class="nav nav-tabs">
    <span class="ygxian"></span>
    <div class="ygdangq">当前位置:</div>    
    <li><a href="{php echo $this->createWebUrl('class')}">班级列表</a></li>
    <li class="active"><a href="{php echo $this->createWebUrl('addclass')}">添加班级</a></li>
</ul>
<div class="main">
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" id="invitative">
        <div class="panel panel-default ygdefault">
            <!-- <div class="panel-heading wyheader">
                班级管理&nbsp;>&nbsp;添加/编辑班级
            </div> -->
            <div class="panel-body">

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">校区</label>
                    <div class="col-sm-9">
                        <!-- <input type="text" name="course_name" class="form-control" value="{$info['course_name']}" /> -->
                    <select name="cate_name" id="school" style="float: left;margin-bottom: 20px">
                       <option value="0" disabled="disabled">请选择</option>
                    </select>
                    <span style="margin-left:20px;width:30px;float:left;" class="control-label">学级</span>
                     <select name="course_name" id="coursecate"  style="float: left;margin-left: 20px;padding-right:45px;">
                        <option value="0" disabled="disabled">请选择</option>
                    </select>
                    <span style="margin-left:20px;width:30px;float:left;" class="control-label">课程</span>
                     <select name="name" id="course"  style="float: left;margin-left: 20px;padding-right:45px;">
                        <option value="0" disabled="disabled">请选择</option>
                    </select>
                    <!-- <select name="name">
                        {loop $cates $item}
                        <option value="{$item['id']}" {if $item['id'] == $info['cou_id']}selected {/if}> {$item['name']}</option>
                        {/loop}
                        </select> -->
                    </div>
                </div>
                <!--      <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">图标</label>
                    <div class="col-sm-9">
                        {php echo tpl_form_field_image('img', $info['img'])}
                    </div>
                </div> -->
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">班级名称</label>
                    <div class="col-sm-9">
                        <input type="text" name="class_name" class="form-control" value="{$info['class_name']}" />
                        <span class="help-block">*例：第一班</span>
                    </div>
                </div>
               
                <!-- <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
                    <div class="col-sm-9">
                        <input type="text" name="sort" class="form-control" value="{$info['sort']}" />
                    </div>
                </div> -->
            </div>
        </div>


        <div class="form-group">
            <input type="submit" name="submit" value="提交" class="btn col-lg-3" style="color: white;background-color: #44ABF7;"/>
            <input type="hidden" name="token" value="{$_W['token']}" />
            <input type="hidden" name="id" value="{$info['id']}" />
        </div>
    </form>
</div>
<script type="text/javascript">
    $(function(){
        // $("#frame-2").addClass("in");
        $("#frame-11").show();
        $("#yframe-11").addClass("wyactive");
        "{if $info}"
            "{if $info['item']=='1'}"
                $('.ygyi2').hide();
                $('.ygyi3').hide();
            "{/if}"
            "{if $info['item']=='2'}"
                $('.ygyi1').hide();
                $('.ygyi3').hide();
            "{/if}" 
            "{if $info['item']=='3'}"
                $('.ygyi1').hide();
                $('.ygyi2').hide();
            "{/if}"            
        "{else}"
            $('.ygyi2').hide();
            $('.ygyi3').hide();
        "{/if}"
        $("select#type").change(function(){
            if($(this).val()=='1'){
                console.log($(this).val())
                $(".ygyi1").show();
                $(".ygyi2").hide();
                $(".ygyi3").hide();  
            }else if($(this).val()=='2'){
                console.log($(this).val())
                $(".ygyi1").hide();
                $(".ygyi2").show();
                $(".ygyi3").hide();  
            }else if($(this).val()=='3'){
                console.log($(this).val())
                $(".ygyi1").hide();
                $(".ygyi2").hide();
                $(".ygyi3").show();  
            }
         })
    })

    $.ajax({
                  type:"post",
                  url:"{$_W['siteroot']}/app/index.php?i={$_W['uniacid']}&c=entry&do=school&m=zh_jypx",
                  dataType:"json",
                  data:{},
                  success:function(res){  
                        console.log(res.list)
                        var all=res.list
                        for(var i=0;i<all.length;i++){
                           console.log(all[i].id)
                           $("#school").append("<option value='"+all[i].id+"'>"+all[i].cate_name+"</option>").attr("selected", true);
                        }
                        // $("#school").append("<option value='"+id+"'>"+thid+"</option>").attr("selected", true);

                  }
              })
     function one(value){
            console.log("执行一")

              $.ajax({
                  type:"post",
                  url:"{$_W['siteroot']}/app/index.php?i={$_W['uniacid']}&c=entry&do=CourseCate&m=zh_jypx",
                  dataType:"json",
                  data:{school_id:value},
                  success:function(res){  

                        console.log(res)
                        var grade=res.list
                        console.log(grade)
                        if(res.code==500){
                          $("#coursecate").css("display","none")
                          $("#course").css("display","none")
                          $("#classes").css("display","none")
                       }else{
                       for(var i=0;i<grade.length;i++){
                          
                           $("#coursecate").append("<option value='"+grade[i].id+"'>"+grade[i].course_name+"</option>").attr("selected", true);
                        }
                        console.log("年级id:"+grade[0].id)
                        two(grade[0].id)
                       }

                  }
              })
     }
     function two(value){
      console.log("执行二")
         $.ajax({
                  type:"post",
                  url:"{$_W['siteroot']}/app/index.php?i={$_W['uniacid']}&c=entry&do=Course&m=zh_jypx",
                  dataType:"json",
                  data:{c_id:value},
                  success:function(res){  

                        console.log(res)
                        var course=res.list
                        console.log(course)

                        for(var i=0;i<course.length;i++){
                           console.log(course[i].id)
                           $("#course").append("<option value='"+course[i].id+"'>"+course[i].name+"</option>").attr("selected", true);
                        }
                        console.log("课程id:"+course[0].id)
                        // three(course[0].id)
                  }
              })
     }

     $("#school").change(function(){
        var school_id=$("#school option:selected").val()
        $("#coursecate").html("")
         $("#course").html("")
        $("#classes").html("")
        // console.log(list)
        if(school_id!=0){
          console.log("获取学校id"+school_id)
          one(school_id)        
        }

    })

    $("#coursecate").change(function(){
        var c_id=$("#coursecate option:selected").val()
        $("#course").html("")
        $("#classes").html("")
        // console.log(list)
        console.log("获取年级id"+c_id)
        two(c_id)

    })

       $("#course").change(function(){
        var cou_id=$("#course option:selected").val()
        var list=$("#classes").html("")
        console.log(list)
        // console.log(list)
        console.log("获取课程id"+cou_id)
        three(cou_id)
    })
</script>